﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Specialized;
using System.Collections;

namespace Gedea.Core.Manager
{
    public static class DataConnection
    {
        public static string DBName = "Hercules";
        public const string _serverName = "ServerName";

        public static string GetConnection()
        {
            return string.Format("Server={0};Integrated security=yes;database={1};",
                ConfigurationManager.AppSettings[_serverName].ToString(),
                //ReadMyUserSettings
                DBName);
        }

        public static string GetMasterConnection()
        {
            return string.Format("Server={0};Integrated security=SSPI;database=master",
                ConfigurationManager.AppSettings[_serverName].ToString());
        }

        public static void Open(System.Data.SqlClient.SqlConnection conn)
        {
            if(conn.State == System.Data.ConnectionState.Closed)
                conn.Open();
        }

        //TO DO: consola de configuraciones para usar este metodo.
        public static void setAppConfigServerName(string serverName)
        {
            Configuration appconfig =
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            //appconfig.AppSettings[_serverName] = serverName;
            //appconfig.Save();
        }

        private static void ReadMySettings(string country)
        {
            string countryKey = "";
            country.Split(' ').ToList().ForEach(x => countryKey += x);
            IDictionary sampleTable = (IDictionary)ConfigurationManager.GetSection(countryKey + "Section");

        }
    }
}
